package com.kunyi.web.service.log.mapper;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kunyi.web.service.log.entity.domain.LogSys;
import com.kunyi.web.service.log.entity.req.LogSysListReq;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName LogSysMapper
 * @Description log_sys表
 * @Author pengjunjun
 * @Date 2024/3/6 14:26
 * @Version 1.0
 **/
@Repository
public interface LogSysMapper extends BaseMapper<LogSys> {
    default List<LogSys> listByReq(LogSysListReq req) {
        LambdaQueryWrapper<LogSys> wrapper = Wrappers.lambdaQuery(LogSys.class)
                .eq(StrUtil.isNotBlank(req.getCode()), LogSys::getCode, req.getCode())
                .eq(Objects.nonNull(req.getEnvType()), LogSys::getEnvType, req.getEnvType())
                .eq(Objects.nonNull(req.getEnvLevel()), LogSys::getEnvLevel, req.getEnvLevel())
                .between(Objects.nonNull(req.getCreateTimeBegin()) && Objects.nonNull(req.getCreateTimeEnd()), LogSys::getCreateTime, req.getCreateTimeBegin(), req.getCreateTimeEnd())
                .orderByDesc(LogSys::getCreateTime);
        return selectList(wrapper);
    }
}
